home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: genew@mindlink.bc.ca (Gene Wirchenko)
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: Sat, 20 Jan 1996 00:32:12 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4dpd94$c25@fountain.mindlink.net>
- References: <4dorr8$i58@cloner3.netcom.com> <4dp5dk$t3r@newsbf02.news.aol.com>
- NNTP-Posting-Host: line069.nwm.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- babycox@aol.com (BabyCox) wrote:
-
-
- >>#define ISPOW2(x) (((x) & 1) ^ 1)
-
- >That will not work, it returns the next lowest MULTIPLE of two, here's
- >what I would do:
-
- >Boolean IsPowerOfTwo(long x)
- >{
- > for(short y = 0;y<=31;y++)
- > {
- > if (x = 1) return true;
- > x >>= 1;
- > }
- > return false;
- >}
-
- This doesn't work! On the first iteration, x will be assigned
- the value 1. This will make the if true and so the "return true;"
- will be done.
-
- If you meant "==", it still doesn't work. It's a LONG test for
- !=0.
-
- Sincerely,
-
- Gene Wirchenko
-
- C Pronunciation Guide:
- y=x++; "wye equals ex plus plus semicolon"
- x=x++; "ex equals ex doublecross semicolon"
-
-